package com.ccb.health.service.impl;

import com.ccb.health.entity.HealthInfo;
import com.ccb.health.entity.User;
import com.ccb.health.mapper.UserMapper;
import com.ccb.health.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> selectUser(User user) {
        return userMapper.selectUser(user);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public int insertUser(User user) {
        return userMapper.insertUser(user);
    }

    @Override
    public HealthInfo selectHealthToday(int id) {
        HealthInfo healthInfo = new HealthInfo();
        healthInfo.setId(id);
        healthInfo.setTime(new Date());
        List<HealthInfo> res = userMapper.selectHealth(healthInfo);
        if(res.size() != 0){
            return res.get(0);
        }
        return null;
    }

    @Override
    public int insertHealth(HealthInfo healthInfo) {
        return userMapper.insertHealth(healthInfo);
    }

    @Override
    public int updateHealth(HealthInfo healthInfo) {
        return userMapper.updateHealth(healthInfo);
    }

    @Override
    public List<HealthInfo> selectHistoryHealth(int id) {
        HealthInfo healthInfo = new HealthInfo();
        healthInfo.setId(id);
        return userMapper.selectHealth(healthInfo);
    }

    @Override
    public List<HealthInfo> selectAllUserInfo() {
        return userMapper.selectAllUserInfo();
    }

    @Override
    public List<HealthInfo> selectUnhealthUser() {
        return userMapper.selectUnhealthUser();
    }

}
